const UserModel = require("../model/goodsData");
const jwt = require("jsonwebtoken");
const {
    secret
} = require("../config");
const catchError = require("../utils/catchError");

class Goods {
    async goodsData(ctx) {
        let {
            cartName,
            cartDes,
            cartImg,
            cartType,
            cartPrice,
            cartSpc,
        } = ctx.request.body;
        // let user = await UserModel.findOne({
        //     cartName
        // });
        // console.log(user);
        // if (user) {
        //     return ctx.body = {
        //         code: 1,
        //         msg: "添加过了",
        //     };
        // }


        let data = await UserModel.create({
            cartName,
            cartDes,
            cartImg,
            cartType,
            cartPrice,
            cartSpc,
        });
        ctx.body = {
            code: 0,
            msg: "添加成功",
        };
    }
    async getGoodsAllData(ctx) {
        // let{
        //     cartName
        // } = ctx.request.body;
        let goods = await UserModel.find({ })
        ctx.body = {
            code: 0,
            msg: "获取成功",
            data:{
                ...goods
            }
        };
    }
    async getGoodsData(ctx) {
        let{
            cartName
        } = ctx.request.body;
        let goods = await UserModel.find({
            cartName
        })
        ctx.body = {
            code: 0,
            msg: "获取成功",
            data:{
                goods
            }
        };
    }
}

module.exports = new Goods();